﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XSTDZ.ERP.Core.Extentions;
using XSTDZ.ERP.Core.Generator;

namespace XSTDZ.ERP.Domain.Models
{
    /// <summary>
    /// 出库单
    /// </summary>
    public partial class ProductDeliveryBill
    {
        public ProductDeliveryBill()
        {
            this.ProductDeliveryBillDetails = new HashSet<ProductDeliveryBillDetail>();
        }

        public ProductDeliveryBill Init()
        {
            if (this.Id == null || this.Id.Equals(Guid.Empty))
            {
                this.Id = (Guid)new SequentialIdentityGenerator().Next;
            }
            this.CreateTime = DateTime.Now;
            this.Deleted = 0;

            return this;
        }
        public ProductDeliveryBill AddDetails(IEnumerable<ProductDeliveryBillDetail> details)
        {
            details.Each(d => AddDetails(d));
            return this;
        }
        public ProductDeliveryBill AddDetails(ProductDeliveryBillDetail detail)
        {
            if (!this.ProductDeliveryBillDetails.Contains(detail))
            {
                if (detail.ProductDeliveryBillID == null || detail.ProductDeliveryBillID.Equals(Guid.Empty))
                {
                    detail.ProductDeliveryBillID = this.Id;
                }
                this.ProductDeliveryBillDetails.Add(detail.Init());
            }
            return this;
        }
    }
}
